Prompt users on instance operations#2547
Conversation
4e8b947 to
0367db2
Compare
f496d80 to
a294e4e
Compare
They are not used. Bug: 511316553
The one location it was accessed was either to verify a value is valid, or using the result from the environment lookup was passed over. The flags are still available, so no functionality is lost with the removal. Bug: 511316553
Specifically, about the various cases it falls back to. The previous version was implicitly relying upon constraints enforced by different helpers and potentially ignoring "failed" `Result` returns. This version expects the operations to all succeed, then acts on those constraints locally. Bug: 511316553
To behave like `FindGroups`, where it allows multiple results to be returned. This will be used to rewrite `selector.cpp::SelectInstance` in the same way as `SelectGroup`. Bug: 511316553
In the same fashion as the `SelectGroup` rewrite, implement `SelectInstance` to be explicit about the various cases and fallbacks. This rewrite also stubs out instance-prompting, though it is not yet implemented. That will be in a follow-up commit, and technically this implementation is just as capable as the previous version. It just fails with a different error message. Bug: 511316553
The new helpers will be able to be reused for instance prompting. This version separates the prompting for a selection label from the display and looking up the group associated with that label. It also adds prompts to the user to make it clearer what label is expected, and catches different error cases separately. One slight downgrade for this version is it removes the functionality to type in a group name directly to select it. However, that functionality was not clearly advertised and unlikely to be faster than typing a numeric label except in cases that seem unlikely for the majority of users. Bug: 511316553
It reuses the group selection logic, then has the user pick an instance within that group. Bug: 511316553
Bug: 511316553
a294e4e to
1131fb0
Compare
| char instance_idx = 'a'; | ||
| for (const auto& instance : group.Instances()) { | ||
| fmt::print(ss, " <{}> {}-{} (id : {})\n", instance_idx++, | ||
| group.GroupName(), instance.name(), instance.id()); |
There was a problem hiding this comment.
nit: Printing the instance names alongside the group name makes it easier for the user to recognize each group. Especially with auto-generated group names.
| if (filter.Empty()) { // try to default | ||
| groups = CF_EXPECT(instance_manager.FindGroups({})); | ||
| } else { | ||
| groups = CF_EXPECT(instance_manager.FindGroups(filter)); | ||
| } |
There was a problem hiding this comment.
Isn't this equivalent to groups = CF_EXPECT(instance_manager.FindGroups(filter));?
| } | ||
| CF_EXPECT(isatty(0), | ||
| "Multiple groups found. Narrow the selection with selector " | ||
| "arguments or run in an interactive terminal."); |
There was a problem hiding this comment.
nit: Running in an interactive terminal is not likely a good option when this error triggers. Drop that part of the message.
| Result<std::vector<std::pair<LocalInstance, LocalInstanceGroup>>> | ||
| InstanceDatabase::FindInstances(const Filter& filter) const { | ||
| CF_EXPECT_LE(filter.instance_names.size(), 1u, | ||
| "Can't find single instance when multiple names specified: " |
There was a problem hiding this comment.
The function name indicates it's looking for multiple instances, this shouldn't be an error.
| } | ||
| Result<std::pair<LocalInstance, LocalInstanceGroup>> FindInstanceWithGroup( | ||
| const Filter& filter) const; | ||
| Result<std::vector<std::pair<LocalInstance, LocalInstanceGroup>>> |
There was a problem hiding this comment.
If multiple instances from the same group match, this will return multiple copies of the same group. Consider changing the return type to vector<pair<Group, vector<Instance>>> or map<Group, vector<Instance>>.
| Result<LocalInstanceGroup> GetDefaultGroup( | ||
| const InstanceManager& instance_manager) { | ||
| const std::vector<LocalInstanceGroup> all_groups = | ||
| CF_EXPECT(instance_manager.FindGroups({})); | ||
| CF_EXPECTF(all_groups.size() == 1, | ||
| "There are {} instance groups, unable to pick one", | ||
| all_groups.size()); | ||
| return all_groups.front(); | ||
| } | ||
|
|
There was a problem hiding this comment.
nit: This seems to be in the wrong commit
| std::string menu = GroupDisplay(groups, DisplayBehavior::LabelGroup); | ||
| std::cout << menu; |
There was a problem hiding this comment.
nit: std::out << GroupDisplay(...);
When an instance-focused operation (eg
logs) is not given selectors or enough selectors, then havecvdprompt the user to select an instance rather than failing. This matches what we do for group-focused operations (remove).Bug: 511316553